<?php

namespace common\models\inventory;

use Yii;

/**
 * This is the model class for table "{{%inventory_batch}}".
 *
 * @property int $id
 * @property int $type_id 票据ID
 * @property int $user_id 电子标签ID
 * @property int $status 状态
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 * @property int $deleted_at 删除时间
 */
class InventoryBatch extends \common\db\ActiveRecord {

    const STATUS_DEFAULT = 0;
    const STATUS_ACTIVE = 10;

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%inventory_batch}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['type_id', 'user_id', 'status', 'created_at', 'updated_at', 'deleted_at'], 'integer'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'type_id' => '票据ID',
            'user_id' => '电子标签ID',
            'status' => '状态',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
            'deleted_at' => '删除时间',
        ];
    }

    public function getLogs() {
        return $this->hasMany(InventoryLog::className(), ['batch_id' => 'id']);
    }

    public function getAmount() {
        return (int) $this->getLogs()->count();
    }

}
